package com.can.Service.Impl;

import com.can.Service.MqTccService;
import io.seata.rm.tcc.api.BusinessActionContext;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MqTccServiceImpl implements MqTccService {
        private final RabbitTemplate rabbitTemplate;

    @Override
    public boolean mqPrepare(int userId) {
        // 预发送消息（实际不投递，仅记录）
        return true;
    }
    @Override
    public boolean mqCommit(BusinessActionContext context) {
        // 实际发送消息
        rabbitTemplate.convertAndSend("exp.fanout", "", context.getActionContext("userId"));
        return true;
    }
    @Override
    public boolean mqCancel(BusinessActionContext context) {
        // 取消时不做处理（或记录日志）
        return true;
    }
}